package com.pybox.api;

import com.pybox.service.TCabinetsService;
import com.pybox.dto.TCabinetsDto;

import com.pybox.dto.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 描述：TCabinets Api
 *
 * @author wuyingkai
 * @date 2018-09-15
 */

@Slf4j
@RequestMapping("/TCabinets")
@Api(tags = "TCabinets管理接口", description = "TCabinets管理接口")
@RestController
public class TCabinetsApi {

    @Autowired
    private TCabinetsService  service;

    @ApiOperation(value = "创建TCabinets", notes = "创建TCabinets")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result<Boolean> save(@RequestBody TCabinetsDto dto) {
        service.create(dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "删除TCabinets", notes = "删除TCabinets")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(name = "id", value = "TCabinets id", dataType = "String", paramType = "path")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        service.delete(id);
        return Result.ok(true);
    }

    @ApiOperation(value = "更新TCabinets", notes = "更新TCabinets")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @ApiImplicitParam(name = "id", value = "TCabinets id", dataType = "String", paramType = "path")
    public Result<Boolean> update(@PathVariable("id") String id, @RequestBody TCabinetsDto dto) {

        service.update(Integer.parseInt(id), dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "查询TCabinets", notes = "查询TCabinets")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "TCabinets id", dataType = "String", paramType = "path")
    public Result<TCabinetsDto> detail(@PathVariable("id") Integer id) {

        return Result.ok(service.detail(id));
    }

    @ApiOperation(value = "分页查询TCabinets", notes = "分页查询TCabinets")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "uuid", value = "uuid", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "customerId", value = "customerId", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "position", value = "position", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "timezone", value = "timezone", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "ip", value = "ip", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "port", value = "port", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "passwd", value = "passwd", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "timeout", value = "timeout", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "openTimeout", value = "openTimeout", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "comments", value = "comments", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "deleted", value = "deleted", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "version", value = "version", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "ctime", value = "ctime", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "creatUserid", value = "creatUserid", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "createUsername", value = "createUsername", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "utime", value = "utime", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "lastUpdate", value = "lastUpdate", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "isOnline", value = "isOnline", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TCabinetsDto>> page(
            @RequestParam(required = false) Integer id,
            @RequestParam(required = false) String uuid,
            @RequestParam(required = false) String customerId,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String position,
            @RequestParam(required = false) String timezone,
            @RequestParam(required = false) String ip,
            @RequestParam(required = false) String port,
            @RequestParam(required = false) String passwd,
            @RequestParam(required = false) String timeout,
            @RequestParam(required = false) String openTimeout,
            @RequestParam(required = false) String comments,
            @RequestParam(required = false) String deleted,
            @RequestParam(required = false) String version,
            @RequestParam(required = false) String ctime,
            @RequestParam(required = false) String creatUserid,
            @RequestParam(required = false) String createUsername,
            @RequestParam(required = false) String utime,
            @RequestParam(required = false) String lastUpdate,
            @RequestParam(required = false) String isOnline,
            @RequestParam(required = true) Integer pageNo,
            @RequestParam(required = true) Integer pageSize) {

        Map<String, String> params = new HashMap<>();

        params.put("uuid", uuid);
       // params.put("customerId", customerId);
        params.put("name", name);
        params.put("position", position);
        params.put("timezone", timezone);
        params.put("ip", ip);
        params.put("port", port);
        params.put("passwd", passwd);
        params.put("timeout", timeout);
        params.put("openTimeout", openTimeout);
        params.put("comments", comments);
        params.put("deleted", deleted);
        params.put("version", version);
        params.put("ctime", ctime);
        params.put("creatUserid", creatUserid);
        params.put("createUsername", createUsername);
        params.put("utime", utime);
        params.put("lastUpdate", lastUpdate);
        params.put("isOnline", isOnline);
        return Result.ok(service.page(pageNo, pageSize, params));
    }

    @ApiOperation(value = "根据串号查询", notes = "查询TCabinets")
    @RequestMapping(value = "/detailByUuid/{uuid}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "uuid", value = "TCabinets uuid", dataType = "String", paramType = "path")
    public Result<TCabinetsDto> getDetailByUUID(@PathVariable("uuid") String uuid) {
        return Result.ok(service.getDetailByUUID(uuid));
    }

    @ApiOperation(value = "口令校验", notes = "口令校验")
    @RequestMapping(value = "/checkCabinetPasswordUnique/{password}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "password", value = "TUsers password", dataType = "String", paramType = "path")
    public Result<Boolean> checkCabinetPasswordUnique(@PathVariable("password") String password) {
        return service.checkCabinetPasswordUnique(password);
    }

}